package com.weige.conver.handler;

import com.alibaba.fastjson.JSONObject;
import com.weige.conver.config.ActivitiConfig;
import com.weige.conver.entity.EnvData;
import com.weige.conver.entity.PosInfo;
import com.weige.conver.entity.ReceiveMessage;
import com.weige.conver.entity.Sig;
import com.weige.conver.service.DeviceService;
import com.weige.conver.service.EnvDataService;
import com.weige.conver.service.RabbitMQService;
import com.weige.conver.utils.DateUtils;
import com.weige.conver.utils.FileUtils;
import com.weige.conver.utils.JsonUtils;
import com.weige.conver.utils.StringSubUtils;
import lombok.SneakyThrows;
import org.apache.commons.lang.StringUtils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 氧气设备物模型转换
 */
public class OxygenHandler implements ConverHandler {

    RabbitMQService rabbitMQService = ActivitiConfig.getBean(RabbitMQService.class);
    DeviceService deviceService = ActivitiConfig.getBean(DeviceService.class);
    EnvDataService envDataService = ActivitiConfig.getBean(EnvDataService.class);

    @SneakyThrows
    @Override
    public void handler(ReceiveMessage receiveMessage) throws IOException {
        String deviceId = receiveMessage.getDevId();
        String deviceName = receiveMessage.getDevName();
        //物联网平台数据配置
        String model = "oxygen";
        String manufactureId = "ShuyanyuanAIGateway";
        String serviceName = "envDataService";
        EnvData env = envDataService.getEnvDataByData(receiveMessage,model,"ox","氧气值","氧气含量传感器测量值","%");
        //判断数据对象是否为空，并上传到RabbitMQ
        if (env != null){
            String data = JSONObject.toJSONString(env);
            rabbitMQService.sendData(data,deviceId,deviceName,model,manufactureId,serviceName);
        }
    }

}
